Added tests for parsley message definitions#47
Conversation
ChrisYx511
left a comment
There was a problem hiding this comment.
Few comments:
- I feel like your tests are redundant. Why are there 2 tests for every message definition when a lot of the messages are testing for the exact same thing. Each test should test something different and they shouldn't just be numbered.
- Watch unnecessary comments. AI loves adding them but your code should explain itself. You should not need a comment to understand your code except when defining stuff values and binary constants (like arbitrary binary values from the docs). Even then you can use good variable naming to avoid it.
You're on the right track! Please review your changes and re-request review!
|
Also please name your PR something more descriptive and include screenshots of coverage and tests passing. |
WalkthroughRemoved an old CAN-message test module, added a new comprehensive parser test module for CAN message definitions, and updated dev dependencies (added pytest-cov). Changes
Sequence Diagram(s)sequenceDiagram
participant Test as pytest test
participant Builder as BitString builder
participant Parser as parsley.parse_fields
participant Specs as Field definitions (MESSAGES / Enum/Numeric/Bitfield/Floating)
participant Output as parsed result
Note over Test,Builder: Arrange — build payload with TIMESTAMP_2
Test->>Builder: assemble bytes / timestamp
Builder->>Parser: pass BitString + message spec
Parser->>Specs: evaluate each field (enum/bitfield/float/ASCII)
Specs-->>Parser: field values
Parser-->>Output: aggregated parsed dict
Output-->>Test: assertions (expected values)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hey @ChrisYx511 I have made the changes.
|
@yashjain128 Please use the "Request Rereview" button so I see it quicker next time. |
ChrisYx511
left a comment
There was a problem hiding this comment.
close! good work! please address some of the systemic issues with the tests you've written
tests/test_message_definitions.py
Outdated
| assert res["curr_state"] == "ACT_STATE_ON" | ||
| assert res["cmd_state"] == "ACT_STATE_OFF" | ||
|
|
||
| def test2_actuator_status(self, bit_str2): |
There was a problem hiding this comment.
how is this test different? your name doesn't tell me
| from pytest import approx | ||
| from parsley.bitstring import BitString | ||
| from parsley.fields import ASCII, Enum, Numeric, Floating, Bitfield | ||
| from parsley.message_definitions import TIMESTAMP_2, MESSAGES |
There was a problem hiding this comment.
I don't see you using the actual message definitions? isn't that the whole point of this test? Why are you building your own fields?
ChrisYx511
left a comment
There was a problem hiding this comment.
Also nit: don't include your issue number like that in the title it's pretty useless. Include a link in your description. Especially since the issue is not even on the same repository.
ca918ba to
2603c96
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/test_message_definitions.py (1)
24-208: Consider adding edge case and error handling tests.The current tests provide excellent happy-path coverage. To make the test suite more robust, consider adding tests for:
- Boundary values (min/max for Numeric fields, empty ASCII strings)
- Invalid enum values that should raise exceptions
- Out-of-range values that exceed field bit lengths
- Malformed payloads (insufficient data for field definitions)
This would help catch potential issues with field validation and error handling in the parsley library.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
pyproject.toml(1 hunks)tests/test_can_messages.py(0 hunks)tests/test_message_definitions.py(1 hunks)
💤 Files with no reviewable changes (1)
- tests/test_can_messages.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_message_definitions.py (3)
src/parsley/bitstring.py (2)
BitString(1-49)push(30-41)src/parsley/fields.py (5)
ASCII(38-62)Enum(64-106)Numeric(108-144)Floating(146-179)Bitfield(199-232)src/parsley/parsley.py (1)
parse_fields(12-27)
🔇 Additional comments (4)
tests/test_message_definitions.py (3)
11-22: LGTM! Well-structured test fixture.The test class and fixture setup is clean and efficient. The fixture properly initializes a BitString with the TIMESTAMP_2 field, and the docstring clearly explains the testing scope.
138-146: Clarify the pressure value discrepancy.There's a mismatch between the comment and the assertion:
- Comment states: "pressure 101325 (0x018B6D)"
- Assertion expects:
pressure == 101229The difference is 96. Please verify whether this is due to:
- A scaling factor or unit conversion in the
Numericfield definition- An error in the comment
- Rounding or precision handling
If this is due to scaling, consider updating the comment to reflect the actual expected decoded value to avoid confusion.
209-211: Clarify the intent of this test.This test parses an empty fields list and asserts an empty result. If the
LEDS_ONmessage intentionally has no body fields beyond the timestamp (already inbit_str2), this test is valid but could benefit from a comment explaining that.However, if
LEDS_ONshould have LED state fields, this test appears incomplete.Please confirm whether
LEDS_ONis expected to have only a timestamp field, or if additional fields should be tested here.pyproject.toml (1)
39-39: No issues found — pytest-cov 7.0.0 exists and is the latest version.The latest pytest-cov release is 7.0.0, uploaded to PyPI on September 9, 2025. The version constraint in pyproject.toml is valid and will not cause dependency resolution failures.
|
@yashjain128 get another review and merge this!! |
|
pls rebase with latest main branch |




For waterloo-rocketry/2025-software-issues#60
Created 46 tests, 2 tests per packet format specified in https://docs.waterloorocketry.com/avionics/rocketcan/packet-format.html
Deleted the old tests. The code currently passes all the tests.
Removed references to broken test_utils.py which will need to be removed from other test files
This change is
Summary by CodeRabbit